package bsc.war.ajax;



import bsc.ejb.entity.Dimension;
import bsc.ejb.entity.DimensionMember;
import bsc.war.delegate.DelegateBSC;
import bsc.war.factory.Factory;
import bsc.war.service.ScoreCardUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.math.NumberUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

/**
 *
 * @author memozac
 */
public class DesignerAddDimensionalCut extends AbstractController  {

     @Override
    protected ModelAndView handleRequestInternal(HttpServletRequest request,
         HttpServletResponse response) throws Exception {
        
        try {
            DelegateBSC delegate = (DelegateBSC) Factory.getBean("DelegateBSC");
            String[] dimensionIds = request.getParameterValues("dimension");
            List<Dimension> dimensions = new ArrayList<Dimension>();
            if(dimensionIds != null)
                for (String idDimension : dimensionIds) {
                    if(NumberUtils.isNumber(idDimension)){
                        Dimension dimension = delegate.findDimension(Long.parseLong(idDimension));
                        if(dimension != null)dimensions.add(dimension);
                    }
                }

            //HashMap<DimensionMember, Boolean> checkedDimensionMembers = new HashMap<DimensionMember, Boolean>();
            List<List<DimensionMember>> dimensionMembers = ScoreCardUtils.getCrossProduct(delegate, dimensions);
            /*for(List<DimensionMember> list : dimensionMembers)
                for(DimensionMember member : list)
                    checkedDimensionMembers.put(member, Boolean.FALSE);*/

            request.setAttribute("dimensionMembers", dimensionMembers);
            //request.setAttribute("checkedDimensionMembers", checkedDimensionMembers);
        } catch (Exception e) { e.printStackTrace(); }
         
         return new ModelAndView("designerAddDimensionalCut");
    }

}
